package java111_2;

import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

public class Day27 {
    // https://ac.nowcoder.com/acm/problem/50039
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {
            int a = in.nextInt();
            int b = in.nextInt();
            int res = 1;
            for(int i = 1; i <= b; i++){
                if(i == 1){
                    res *= a;
                }else {
                    res *= a-1;
                }
                res %= 109;
            }
            System.out.println(res);
        }
    }


    // https://www.nowcoder.com/practice/e88b41dc6e764b2893bc4221777ffe64
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int xs = in.nextInt(), ys = in.nextInt(), xt = in.nextInt(), yt = in.nextInt();
        String[] arr = new String[n];
        char[][] chars = new char[n][m];
        for(int i = 0; i < n; i++){
            arr[i] = in.next();
            chars[i] = arr[i].toCharArray();
        }
        if(chars[xt-1][yt-1] == '*'){
            System.out.println(-1);
        }
    }


    // https://www.nowcoder.com/practice/4edf6e6d01554870a12f218c94e8a299
    public int minmumNumberOfHost (int n, int[][] startEnd) {
        Arrays.sort(startEnd, (x1, x2) -> {
            return x1[0] <= x2[0] ? -1 : 1;
        });
        Queue<Integer> heap = new PriorityQueue<>();
        for(int i = 0; i < startEnd.length; i++){
            if(heap.isEmpty()){
                heap.add(startEnd[i][1]);
            } else {
                if(heap.peek() <= startEnd[i][0]){
                    heap.remove();
                    heap.add(startEnd[i][1]);
                } else {
                    heap.add(startEnd[i][1]);
                }
            }
        }
        return heap.size();
    }
}
